﻿<!DOCTYPE html>
<html lang="zn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title> 修改密码 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="static/css/x-admin.css" media="all">
    <script src="static/js/jquery.min.js" ></script>
    <style>
      .change-password {  width:520px; margin:20px auto;}
      .passmargin #but{background-color: #3467cc;font-size: 16px;}
      .layui-form .layui-form-item label, .layui-form .layui-form-item input{font-size:14px}
       .msg{color:#D9001B;font-size:14px;height:20px;line-height: 20px;text-align: center;}
    </style>
    <script type="text/javascript">
    	$(function(){
    		$("#but").click(function(){
    			if($("#oldpwd").val()==""){
    				$(".msg").text("密码不允许为空")
    				return;
    			}
    			var reg=/^(.){6,20}$/;
    			if($("#newpwd").val()==""){
    				$(".msg").text("新密码不允许为空")
    				return;
    			}else if(reg.test($("#newpwd").val())==false){
    				$(".msg").text("不符合规则，满足6-20位")
    				$("#newpwd").val("");
    				return;
    			}else if($("#newpwd").val()!=$("#surenewpwd").val()){
    				$(".msg").text("两次密码输入不一致")
    				$("#surenewpwd").val("");
    				return;
    			}else{
    				//修改密码
					$.ajax({
						url:"admin/adminUpdatePwd",
						type:"post",
						dataType:"json",
						data:{
							oldpwd:$("#oldpwd").val(),
							newpwd:$("#newpwd").val()
						},
						success:function(result){
							if(result.message=="verifyerror"){   //原密码错误  
								$(".msg").text("对不起，原密码错误")
								$("#oldpwd").val("");
							}else if(result.message=="error"){
								$(".msg").text("对不起，修改失败")
							}else if(result.message=="success"){
								$("#oldpwd").val("");
								$("#newpwd").val("");
								$("#surenewpwd").val("");
								$(".msg").text("重置成功")
							}
						}
					});
    			}
    		});
    	});
    </script>
</head>

<div class="x-body">
    <form action="" class="layui-form change-password" >
    	<p class="msg"></p>
        <div class="layui-form-item passmargin password-box">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" id="oldpwd" required="required" placeholder="请输入原来密码"
                    autocomplete="off" class="layui-input password-box">
            </div>
            </div>
            <div class="layui-form-item passmargin">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" id="newpwd" required="required" placeholder="设置6到20位登录密码"
                        autocomplete="off" class="layui-input password-box">
                </div>
            </div>
            <div class="layui-form-item passmargin">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" id="surenewpwd" required="required" placeholder="6-20位密码，区分大小写"
                            autocomplete="off" class="layui-input password-box">
                    </div>  
           </div>                 
           <div class="layui-form-item passmargin">
                    	<label class="layui-form-label"></label>
                        <button type="button" class="layui-btn layui-btn-lg" id="but">确 认</button>
           </div>


    </form>
	</div>
  </body>
</html>